/**
 * Created by hjqi on 2016/5/19.
 */
module.controller('ServiceInstanceController',
    function ($scope,$rootScope,$state,$location, $stateParams,k8sService ){

        //inherit from ServiceDetailController

        $scope.curItem  = undefined;
        $scope.loadlog = false;
        $scope.loadconsole = false;
        $scope.instance = {};
        $scope.setItem = function(item,idx){
            $scope.curItem = item;
        };
        $scope.getlog = function(idx,item){
            $scope.$broadcast('getLogEvt-'+idx,item);
        }
        $scope.getConsole = function(idx,item){
            $scope.$broadcast('getConsoleEvt-'+idx,item);
        }
        $scope.getHistoryStatus = function(idx,item){
            if (item.lastState) {
                if (item.lastState.terminated) {
                    delete item.lastState.terminated.containerID;
                    delete item.lastState.terminated.finishedAt;
                    delete item.lastState.terminated.startedAt;
                }
                var historyStatus = {
                    lastState: item.lastState
                }
                $scope.tabs.historyStatus = jsyaml.safeDump(historyStatus).toString();
            }
        }
        /**
         * 传递事件给InstanceMonitorController
         * @param idx
         * @param item
         */
        $scope.getMonitor = function(idx,item){
           // console.log("broadcast the event of getMonitorEvt-"+idx+",item="+JSON.stringify( item ) ) ;
            $scope.setItem(  item ,idx ) ;
            $scope.$broadcast('getMonitorEvt-'+idx,item);
        }

    }
);